/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Message;

import ExcelAccess.ExcelFormat;
import java.io.Serializable;
import java.util.ArrayList;

/**
 *
 * @author workshop
 */
public class QueryMessage implements Serializable{
    // from client side
    public int queryType = 0;
    public static final int TERMINATE = 0;
    public static final int SEARCH = 1;
    public static final int TRANSFER = 2;
    public static final int UPDATE = 3;
    public static final int INSERT = 4;
    public static final int DELETE = 5;
    public static final int CONFIRM = 6;
    public static final int CANCEL = 7;
    public static final int TRANSFER_BACK = 8; 
    public static final int GENERAL_SEARCH = 9;
    public static final int GENERATE_REPOT = 10;
    
    public String tableName = null;
    public ArrayList<String> outputFields = null;
    public ArrayList<String> constraintFields = null;
    public ArrayList<String> constraintValues = null;    
    public ArrayList<Integer> constraintType = null;
    public ArrayList<String> updateFields = null;
    public ArrayList<String> updateValues = null;
    public ArrayList<Integer> updateType = null;
    public static final int STRING_TYPE = 0;
    public static final int INT_TYPE = 1;
    public static final int DATE_TYPE = 2;
    public ArrayList<Boolean> isFuzzSearch = null; // indict whether these constraint is fuzz search or not
   
    public String fileName = null;
    public long fileLength;
    
    private static final long serialVersionUID = 9019685012367757690L;
    
    // from server side
    public int queryStatus;
    public String message = null;
    public ArrayList<String> result;
    
    public void SetQueryResult(int queryStatus, ArrayList<String> result){
        this.queryStatus = queryStatus;
        if(queryStatus == 0){
            this.message = "successful";
            this.result = result;
            return;
        }
        switch(queryStatus){
            case 1:
                this.message = "Database connection lost;\n";
                break;
            case 2:
                this.message = "SQL Error;\n";
                break;
            case 3:
                this.message = "Plsease change the file name!\n";
                break;
            case 4:
                this.message = "File creation problem!\n";
                break;
            case 5:
                this.message = "File write problem!\n";
                break;
            case 6:
                this.message = "Excel file read problem!\n";
                break;
            case 7:
                this.message = "Object does not exist in the indicated excel file!\n";
                break;
            case 8:
                this.message = "Object already existed but content is different!\n";
                break;
            case 9:
                this.message = "File requested not exist! Please update database!\n";
                break;
            case 10:
                this.message = "File requested cannot read!\n";
                break;
            case 11:
                this.message = "Please clear server user folder!\n";
                break;
        }
    }
    
    public void FormatFields(){
        outputFields = ExcelFormat.convertFieldNames(this.outputFields);
        constraintFields = ExcelFormat.convertFieldNames(this.constraintFields);
        updateFields = ExcelFormat.convertFieldNames(this.updateFields);
        updateValues = ExcelFormat.addBackSlashSQL(this.updateValues);
        constraintValues = ExcelFormat.addBackSlashSQL(this.constraintValues);
    }
}
